﻿using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace SMSTasker
{
	public static class WinAPI
	{
	    [DllImport("coredll.dll", SetLastError = true)]
	    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
	    [DllImport("coredll.dll", SetLastError = true)]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("coredll.dll")]
        private static extern IntPtr SetCapture(IntPtr hWnd);
        [DllImport("coredll.dll")]
        private static extern IntPtr GetCapture();
        [DllImport("coredll", EntryPoint = "GetDC", SetLastError = true)]
        public static extern IntPtr GetDC(IntPtr hWnd);
        [DllImport("coredll.dll", EntryPoint="ReleaseDC", SetLastError=true)]
        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

        [DllImport("coredll.dll")]
        public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        
        public static IntPtr GetHWnd(Control ctrl)
        {
            IntPtr hOldWnd = GetCapture();
            ctrl.Capture = true;
            IntPtr hWnd = GetCapture();
            ctrl.Capture = false;
            SetCapture(hOldWnd);
            return hWnd;
        } 
	}
}